package com.css.fxfzaqbz.modules.base.service.impl;


import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: fxfzypg
 * @Author: lhl
 * @CreateDate: 2022/11/25 9:44
 */
//public class AbkznlfbServiceImpl {
//    @Resource
//    PreAssessResultRepository preAssessResultRepository;
//    @Resource
//    PbeService pbeService;
//    @Resource
//    HosPeoRepository hosPeoRepository;
//
//    /**
//     * @param activityId    活动Id
//     * @param abEntity1List 每个结构的破坏比率集合
//     * @param i             地震烈度
//     * @param province      省
//     * @param city          市
//     * @param prefecture    县
//     */
//    // @Override
//    public void seiCapCalculation(String activityId, int i, List<AbEntity1> abEntity1List,
//                                  String province, String city, String prefecture) {
//        //先删除该活动下的老的抗震能力分布的值
//        preAssessResultRepository.delSeiCapCalByTaskId(activityId);
//
//        //各个结构的占比
//        BigDecimal highStructureTypeProp = null;
//        BigDecimal steelStructureTypeProp = null;
//        BigDecimal hntStructureTypeProp = null;
//        BigDecimal zhStructureTypeProp = null;
//        BigDecimal zmStructureTypeProp = null;
//        BigDecimal sotlStructureTypeProp = null;
//        BigDecimal woodStructureTypeProp = null;
//        BigDecimal stoneStructureTypeProp = null;
//        BigDecimal otherStructureTypeProp = null;
//
//        //好轻中严毁
//        BigDecimal basicallyIntact = null;
//        BigDecimal minorDamage = null;
//        BigDecimal moderateDamage = null;
//        BigDecimal seriousDamage = null;
//        BigDecimal damage = null;
//
//        //抗震能力分布的实体
//        SeiCapDistribution seiCapDistribution = new SeiCapDistribution();
//
//        Map<String, AbEntity1> entity1Map = new HashMap<>();
//        if (PlatformObjectUtils.isNotEmpty(abEntity1List)) {
//            for (AbEntity1 abEntity1 : abEntity1List) {
//                entity1Map.put(abEntity1.getStructureType(), abEntity1);
//            }
//            //获取到该省市县下所有的结构存到list
//            //城镇住宅，城镇非住宅，农村独立住宅，农村集合住宅，农村非住宅
//            //查相应的库。。。。。。
//            List<String> list = new ArrayList<>();
//
//            BigDecimal result = new BigDecimal(0.0);
//            for (int a = 0; a < list.size(); a++) {
//                if (entity1Map.containsKey(list.get(a))) {
//                    AbEntity1 abEntity1 = entity1Map.get(list.get(a));
//                    basicallyIntact = abEntity1.getA();
//                    minorDamage = abEntity1.getB();
//                    moderateDamage = abEntity1.getC();
//                    seriousDamage = abEntity1.getD();
//                    damage = abEntity1.getE();
//                } else {
//                    //不存在该结构类型的比率
//                    //处理。。。。。。
//                }
//
//                /**获取到这个省市县范围内包括相交的公里格网的数据
// * public List<PbeEntity> getPbeInfo(String province, String city, String prefecture) {
// *     String sql="SELECT *,ST_AsText(geom) geomText FROM data_pbe t WHERE isdelete='"+YNEnum.N.toString()
// *     + "' and province=? and city=? and prefecture=?"
// *     return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(PbeEntity.class),province,city,prefecture);
// * }
// */
//                List<PbeEntity> pbeEntityList = pbeService.getPbeInfo(province, city, prefecture);
//                for (PbeEntity pbeEntity : pbeEntityList) {
//                    StructuralProportionVo structuralProportion = this.getStructuralProportion(pbeEntity);
//                    if ("城镇".equals(structuralProportion.getTownorcontry())) {
//                        highStructureTypeProp = structuralProportion.getDhpTownHighTatio();
//                        steelStructureTypeProp = structuralProportion.getDhpTownSteelTatio();
//                        hntStructureTypeProp = structuralProportion.getDhpTownBetonTatio();
//                        zhStructureTypeProp = structuralProportion.getDhpTownBrickTatio();
//                        zmStructureTypeProp = structuralProportion.getDhpTownMasonryTatio();
//                        sotlStructureTypeProp = structuralProportion.getDhpTownSoilTatio();
//                        woodStructureTypeProp = structuralProportion.getDhpTownWoodTatio();
//                        stoneStructureTypeProp = structuralProportion.getDhpTownStoneTatio();
//                        otherStructureTypeProp = structuralProportion.getDhpTownOtherTatio();
//                    } else {
//                        highStructureTypeProp = structuralProportion.getDhpVillageHighTatio();
//                        steelStructureTypeProp = structuralProportion.getDhpVillageSteelTatio();
//                        hntStructureTypeProp = structuralProportion.getDhpVillageBetonTatio();
//                        zhStructureTypeProp = structuralProportion.getDhpVillageBrickTatio();
//                        zmStructureTypeProp = structuralProportion.getDhpVillageMasonryTatio();
//                        sotlStructureTypeProp = structuralProportion.getDhpVillageSoilTatio();
//                        woodStructureTypeProp = structuralProportion.getDhpVillageWoodTatio();
//                        stoneStructureTypeProp = structuralProportion.getDhpVillageStoneTatio();
//                        otherStructureTypeProp = structuralProportion.getDhpVillageOtherTatio();
//                    }
//
//                    //抗震能力值
//                    BigDecimal seiCapIndex = basicallyIntact.multiply(new BigDecimal(FxfzConstants.INTACT))
//                            .add(minorDamage.multiply(new BigDecimal(FxfzConstants.SLIGHT)))
//                            .add(moderateDamage.multiply(new BigDecimal(FxfzConstants.SECONDARY)))
//                            .add(seriousDamage.multiply(new BigDecimal(FxfzConstants.SERIOUS)))
//                            .add(damage.multiply(new BigDecimal(FxfzConstants.DAMAGE)));
//                    String structureType = list.get(a);
//                    if (FxfzConstants.HIGH_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(highStructureTypeProp);
//                    } else if (FxfzConstants.STEEL_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(steelStructureTypeProp);
//                    } else if (FxfzConstants.HNT_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(hntStructureTypeProp);
//                    } else if (FxfzConstants.ZH_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(zhStructureTypeProp);
//                    } else if (FxfzConstants.ZM_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(zmStructureTypeProp);
//                    } else if (FxfzConstants.SOIL_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(sotlStructureTypeProp);
//                    } else if (FxfzConstants.WOOD_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(woodStructureTypeProp);
//                    } else if (FxfzConstants.STONE_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(stoneStructureTypeProp);
//                    } else if (FxfzConstants.OTHER_STRUCTURE.equals(structureType)) {
//                        result = seiCapIndex.multiply(otherStructureTypeProp);
//                    }
//                    seiCapDistribution.setId(UUIDGenerator.getUUID());
//                    seiCapDistribution.setTaskId(activityId);
//                    seiCapDistribution.setProvince(province);
//                    seiCapDistribution.setCity(city);
//                    seiCapDistribution.setCounty(prefecture);
//                    seiCapDistribution.setSeismicCapacityValue(result.setScale(2, BigDecimal.ROUND_UP));
//                    seiCapDistribution.setPbeId(pbeEntity.getPbeId());
//                    seiCapDistribution.setGeom(pbeEntity.getGeomText());
//                    seiCapDistribution.setDz_intensity(i + "");
//                    preAssessResultRepository.saveSeismicCapacity(seiCapDistribution);
//
//                }
//            }
//        }
//    }
//
//    // @Override
//    public StructuralProportionVo getStructuralProportion(PbeEntity pbeEntity) {
//        //获取到这个省市县的人口和建筑物概况的数据
//        HosPeoEntity hosPeoEntity = hosPeoRepository.findHosPeo(pbeEntity.getProvince(), pbeEntity.getCity(), pbeEntity.getCounty());
//        if (hosPeoEntity == null) {
//            return null;
//        }
//        StructuralProportionVo structuralProportionVo = new StructuralProportionVo();
//        BeanUtils.copyProperties(hosPeoEntity, structuralProportionVo);
//        structuralProportionVo.setTownorcontry(pbeEntity.getTownorcontry());
//        if ("城镇".equals(structuralProportionVo.getTownorcontry())) {
//            structuralProportionVo.setDhpTownHighTatio(structuralProportionVo.getDhpTownHighTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownSteelTatio(structuralProportionVo.getDhpTownSteelTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownBetonTatio(structuralProportionVo.getDhpTownBetonTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownBrickTatio(structuralProportionVo.getDhpTownBrickTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownMasonryTatio(structuralProportionVo.getDhpTownMasonryTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownSoilTatio(structuralProportionVo.getDhpTownSoilTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownWoodTatio(structuralProportionVo.getDhpTownWoodTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownStoneTatio(structuralProportionVo.getDhpTownStoneTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpTownOtherTatio(structuralProportionVo.getDhpTownOtherTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//        } else {
//            structuralProportionVo.setDhpVillageHighTatio(structuralProportionVo.getDhpVillageHighTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageSteelTatio(structuralProportionVo.getDhpVillageSteelTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageBetonTatio(structuralProportionVo.getDhpVillageBetonTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageBrickTatio(structuralProportionVo.getDhpVillageBrickTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageMasonryTatio(structuralProportionVo.getDhpVillageMasonryTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageSoilTatio(structuralProportionVo.getDhpVillageSoilTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageWoodTatio(structuralProportionVo.getDhpVillageWoodTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageStoneTatio(structuralProportionVo.getDhpVillageStoneTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//            structuralProportionVo.setDhpVillageOtherTatio(structuralProportionVo.getDhpVillageOtherTatio().divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_DOWN));
//        }
//        return structuralProportionVo;
//    }
//
//}
